#include <iostream>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
using namespace std;

int main()
{
    cout << "I am a process, pid: "<< getpid()<<endl;
    pid_t id = fork();


    if (id == 0)
    {
        cout << "我是子进程，pid: " << getpid() << ", ppid: " << getppid() << endl;
        sleep(1);
        
    }
    else 
    {
        cout << "我是父进程，pid: "<< getpid() <<endl;
        sleep(20);
    }

    //if (id == 0)
    //{
    //    while(1)
    //    {
    //        cout << "我是子进程，pid: " << getpid() << ", ppid: " << getppid() << endl;
    //        sleep(2);
    //    }
    //}
    //else 
    //{
    //    cout << "我是父进程，即将退出"<<endl;
    //    sleep(4);
    //}

    return 0;
}
